﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NStore.Domain.Violations;
using Rhino.Mocks;

namespace NStore.Domain.Tests
{
    [TestClass]
    public class ProductTest
    {
        [TestMethod]
        public void ProductInstance_CallConstructor_NotInitializeValidator()
        {
            Assert.IsNull(new Product().Validator);
        }

        [TestMethod]
        public void ProductInstance_CallOnIsValid_ShouldCallOnGetRuleViolationsOfValidatorProperty()
        {
            ProductValidator mockProductValidator = MockRepository.GenerateMock<ProductValidator>(new List<Product>());
            Product product = new Product {Validator = mockProductValidator};
            mockProductValidator.Stub(m => m.GetRuleViolations(product)).Return(new List<RuleViolation>());

            product.IsValid();

            mockProductValidator.AssertWasCalled(p => p.GetRuleViolations(product));
        }

        [TestMethod]
        public void ProductInstance_CallOnGetRuleViolations_ShouldCallOnGetRuleViolationsOfValidatorProperty()
        {
            ProductValidator mockProductValidator = MockRepository.GenerateMock<ProductValidator>(new List<Product>());

            Product product = new Product { Validator = mockProductValidator };
            product.GetRuleViolations();

            mockProductValidator.AssertWasCalled(p => p.GetRuleViolations(product));
        }
    }
}
